package com.nhjf.dao.teachers;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.TeacherHasCoursesType;
import com.nhjf.pojo.qo.teachers.TeacherHasCoursesTypeQo;
@Repository
public class TeacherHasCoursesTypeDao extends BaseDao<TeacherHasCoursesType, TeacherHasCoursesTypeQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, TeacherHasCoursesTypeQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("teacherId", qo.isSeachTeacher()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("coursesTypeId", qo.isSeachCoursesType()?FetchMode.JOIN:FetchMode.SELECT);
			if(qo.getTeacherId()!=null) {
				criteria.add(Restrictions.eq("teacherId.id",qo.getTeacherId()));
			}
			if(qo.getCoursesTypeId()!=null) {
				criteria.add(Restrictions.eq("coursesTypeId.id",qo.getCoursesTypeId()));
			}
		}
		return criteria;
	}
	@Override
	protected Class<TeacherHasCoursesType> getEntityClass() {
		// TODO Auto-generated method stub
		return TeacherHasCoursesType.class;
	}

}
